package modelLayer;

//import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class SalesOrder {
	
	private String salesOrderID;
	private Date date;
	private double amount;
	private int deliveryStatus;
	private Customer customer;
	private Invoice invoice;
	private List<PartSalesOrder> pso;
	
	
	public SalesOrder()
	{
		initializeList();
		setDate();
	}	
	
	public SalesOrder(String salesOrderID)
	{
		this.salesOrderID = salesOrderID;
	}
	
	public SalesOrder(Date date)
	{
		this.date = date;
	}
	
	
	
	public void setDate()
	{
		date = new Date();	
	}
	
	public void setDate(Date date)
	{
		this.date = date;
	}
	
	public Date getDate()
	{
		return date;
	}


	public String getSalesOrderID() 
	{
		return salesOrderID;
	}


	public void setSalesOrderID(String salesOrderID) 
	{
		this.salesOrderID = salesOrderID;
	}


	public double getAmount() 
	{
		return amount;
	}


	public void setAmount(double amount) 
	{
		this.amount = amount;
	}
	
	public double calculateTotalAmount()
	{
		double e = 0;
		
		for(PartSalesOrder p : pso)
		{
			e = e + p.getTotalamount();
		}
		return e;
	}


	public int getDeliveryStatus() 
	{
		return deliveryStatus;
	}


	public void setDeliveryStatus(int deliveryStatus) 
	{
		this.deliveryStatus = deliveryStatus;
	}


	public Customer getCostumer() 
	{
		return customer;
	}


	public void setCostumer(Customer customer) 
	{
		this.customer = customer;
	}


	public Invoice getInvoice() {
		return invoice;
	}


	public void setInvoice(Invoice invoice) {
		this.invoice = invoice;
	}
	
	
	//List controller
	
	public void initializeList()
	{
		pso = new LinkedList<PartSalesOrder>();
	}
	
	public List<PartSalesOrder> getList()
	{
		return pso;
	}
	
	//crud for list..
	
	public void addPartSalesOrder(PartSalesOrder pso)
	{
		this.pso.add(pso);
	}
	
	public PartSalesOrder findPartSalesOrder(String partSalesOrderID)
	{
		int i = 0;
		boolean found = false;
		PartSalesOrder psoObj = null;
		while(i < pso.size() && !found)
		{		
			psoObj = pso.get(i);
			if(psoObj.getPartSalesOrderID().equalsIgnoreCase(partSalesOrderID))
			{
				found = true;
			}
			i++;
		}
		return psoObj;
		
	}
	
	
	public void deletePartSalesOrder(PartSalesOrder pso)
	{
		this.pso.remove(pso);
	}
	
	
	

}
